package pattern.singleton.lazy;

/**
 * 懒汉式单例
 * 在外部需要使用的时候实例化
 * @author: jxj
 * @create: 2019-04-22
 **/
public class LazyDoubleCheckSingleton {
    //静态块 公共内存区域
    private volatile static LazyDoubleCheckSingleton lazyDoubleCheckSingleton=null;
    private LazyDoubleCheckSingleton(){}
    public static LazyDoubleCheckSingleton getInstance(){
        if(null==lazyDoubleCheckSingleton){
            synchronized (LazyDoubleCheckSingleton.class){
                if(null==lazyDoubleCheckSingleton){
                    lazyDoubleCheckSingleton=new LazyDoubleCheckSingleton();
                    //1.分配内存给这个对象
                    //2.初始化对象
                    //3.设置lazy指向刚分配的内存地址
                    //4.初次访问对象
                }
            }
        }
        return lazyDoubleCheckSingleton;
    }
}
